package shujia.day15;
/*
    2、自己造一个类，实现Runnable接口，实现run方法，创建该线程类的对象，借助Thread类构造方法，创建一个线程对象，启动【启动线程】
 */
class MyRunnable1 implements Runnable{
    @Override
    public void run() {
        for(int i=1;i<=200;i++){
            //Thread.currentThread() -- 当前是哪一个线程在执行run方法的代码逻辑
            System.out.println(Thread.currentThread().getName() + " - "+i);
        }
    }
}

public class MyRunnableDemo1 {
    public static void main(String[] args) {
        MyRunnable1 myRunnable1 = new MyRunnable1();

        //Thread类构造方法
        //Thread(Runnable target)
        //分配一个新的 Thread对象。
//        Thread t1 = new Thread(myRunnable1);
//        Thread t2 = new Thread(myRunnable1);
//        Thread t3 = new Thread(myRunnable1);

        //Thread(Runnable target, String name)  传入Runnable对象的同时给线程起一个名字
        //分配一个新的 Thread对象。
        Thread t1 = new Thread(myRunnable1,"张成阳");
        Thread t2 = new Thread(myRunnable1,"方直");
        Thread t3 = new Thread(myRunnable1,"杨浩东");

        t1.start();
        t2.start();
        t3.start();
    }
}
